﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YYS
{
    public class WebClientEx : System.Net.WebClient
    {
        public WebClientEx(int timeout)
        {
            this._TimeOut = timeout;
        }

        public WebClientEx()
        {

        }

        private int _TimeOut = 100;
        public int TimeOut
        {
            get { return _TimeOut; }
            set { _TimeOut = value; }
        }

        protected override System.Net.WebRequest GetWebRequest(Uri address)
        {
            System.Net.ServicePointManager.DefaultConnectionLimit = 512;
            var httpWebRequest = (System.Net.HttpWebRequest)base.GetWebRequest(address);
            httpWebRequest.ServicePoint.Expect100Continue = false;
            httpWebRequest.ServicePoint.UseNagleAlgorithm = false;
            httpWebRequest.ServicePoint.ConnectionLimit = 65500;
            httpWebRequest.AllowWriteStreamBuffering = false;
            httpWebRequest.Proxy = null;
            httpWebRequest.Timeout = _TimeOut * 1000;
            httpWebRequest.ReadWriteTimeout = _TimeOut * 1000;
            //httpWebRequest.KeepAlive = false;              
            return httpWebRequest;
        }
    }
}
